Python - SDK
The CallSDK is designed to provide a straightforward and efficient way to implement flash call (missed call) authentication within your Python applications. It abstracts the complexities of interacting directly with the underlying API, allowing developers to quickly and easily integrate phone number verification through missed calls. This SDK is particularly useful for scenarios requiring secure and rapid user authentication.
Installation
Install the SDK
pip install betatel-sdk
Import the SDK
from betatel-sdk import CallSDK # or from CallSDK import CallSDK if local.
Initialization
Create an instance of the CallSDK:
api_key = "YOUR_API_KEY" # Replace with your API key
call_sdk = CallSDK(api_key)
Replace YOUR_API_KEY
with the actual value provided by your service.
Security Notice:
Keep your API key secure. Do not expose it in client-side code or commit it to version control. Store it securely and retrieve it from a safe source.
Usage: Initiating a Flash Call
Use the flash method:
def initiate_flash_call(callee, caller, max_ring_time=5):
try:
success = call_sdk.flash(callee, caller, max_ring_time)
if success:
print("Flash call initiated successfully!")
else:
print("Flash call initiation failed.")
except requests.exceptions.HTTPError as e:
print(f"Error initiating flash call: {e}")
# Example usage:
initiate_flash_call("+15551234567", "+15559876543")
Phone Number Formatting:
Ensure that the phone numbers you provide are in the E.164 format (e.g., +15551234567) or the format expected by your API. Consult your API documentation for specifics.
Parameter | Type | Description |
---|---|---|
callee | string | The phone number of the person to be called. |
caller | string | The phone number of the person making the call. |
maxRingTime | int | (Optional) The maximum time (in seconds) to ring before the call is considered failed. |
Error Handling:
The flash method will raise a requests.exceptions.HTTPError
if the API call fails or returns a non-200
status code. Wrap your flash call within a try...except
block to handle these errors gracefully.
Example of complete integration
from betatel-sdk import CallSDK # or from CallSDK import CallSDK if local.
import requests
api_key = "YOUR_API_KEY_HERE" # Replace with your API key
call_sdk = CallSDK(api_key)
def initiate_flash_call(callee, caller, max_ring_time=5):
try:
success = call_sdk.flash(callee, caller, max_ring_time)
if success:
print("Flash call initiated successfully!")
else:
print("Flash call initiation failed.")
except requests.exceptions.HTTPError as e:
print(f"Error initiating flash call: {e}")
initiate_flash_call("+15551234567", "+15559876543")
Important notes
- Ensure that the phone numbers are in the correct format expected by your API.
- Consult your API documentation for any specific requirements or limitations.
- Keep your API key secure and do not expose it in client-side code.